home *** CD-ROM | disk | FTP | other *** search
/ Plug-In Power Pack for Netscape Communicator / Plug-In Power Pack for Netscape Communicator.iso / plugins / dataviews / dvtools / examples / utilities / tx2vt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-08  |  7.0 KB  |  213 lines

  1. #ifndef    lint
  2. static char SccsId[]= "@(#)tx2vt.c    V1.11    5/2/95";
  3. #endif
  4. /* ====================================================================
  5.    tx2vt - convert hardware texts to vector texts in a viewfile
  6.    --------------------------------------------------------------------
  7.    VERSION        1.0
  8.    SYNOPSIS       tx2vt <device-string> <viewfile-source> <viewfile-destination> [<fontfile>] {[<fontheight> <fontwidth>] [<scale>]}
  9.    DESCRIPTION    Converts all hardware texts in a viewfile to software
  10.                   generated vector texts.  Uses a new routine
  11.                   VOdrObReplace().  The regular roman.vf font is used
  12.                   unless otherwise specified and sizes are scaled to
  13.                   match the original hardware texts as closely as
  14.                   possible.  The user should then be able to go into
  15.                   DV-Draw and make the appropriate fine changes if
  16.                   necessary.  The utility will correctly convert all
  17.                   hardware texts in included subdrawings; referenced
  18.                   subdrawings will be left as is.
  19.  
  20.    HOW IT WORKS
  21.  
  22.        There are three possibilities requiring consideration in a
  23.    view when converting:
  24.  
  25.        (1) if it is a regular text object (OT_TEXT):
  26.            (a) create a version in vector text (VOvtCreate);
  27.            (b) size it so that it will approximate the height and
  28.                width of the regular text (VOtxBox, VOvtBox, VOvtAtSet);
  29.            (c) replace the regular text with the vector text
  30.                (using VOdrObReplace).
  31.        (2) if it is a subdrawing (OT_SUBDRAWING), recursively do a
  32.            TobForEachSubobject with the drawing object associated with
  33.            the subdrawing.
  34.        (3) if it is anything else, ignore it.
  35.  
  36.    EXAMPLE      tx2vt console dan.v out.v gothen.vf
  37.    ================================================================= */
  38.  
  39. #include "std.h"
  40. #include "dvstd.h"
  41. #include "dvtools.h"
  42. #include "VOstd.h"
  43. #include "VOfundecl.h"
  44. #include "Tfundecl.h"
  45.  
  46. /* Global forward function declarations */
  47. int main V_P_ ((int argc, char *argv[]));
  48.  
  49.  
  50. #define ARGBLOCK argblock
  51. typedef struct
  52. {
  53.   OBJECT d;
  54.   char *f;
  55. } argblock;
  56.  
  57. DRAWPORT drawport;
  58. FLOAT fh = 1, fw = 1, scale = 0;
  59. INT userset = 0;
  60.  
  61. /* Local forward function declarations */
  62. ADDRESS ReplaceTextWithVtext V_P_ ((OBJECT object, argblock * arg));
  63. LOCAL char *VIstrclone V_P_ ((char *str));
  64.  
  65. LOCAL CHAR ErrMsg[]= "Wrong number of arguments.\n";
  66. LOCAL CHAR Usage[]= "Usage: %s <device-string> <viewfile-source> <viewfile-destination>\n           [<fontfile>] {[<fontheight> <fontwidth>] [<scale>]}\n";
  67. LOCAL CHAR *DVpath = NULL;      /* Use value of DVPATH config variable */
  68.  
  69. int 
  70. main (argc, argv)
  71.      int argc;
  72.      char *argv[];
  73. {
  74.   VIEW view;
  75.   SCREEN_OBJECT screen;
  76.   ARGBLOCK arg;
  77.  
  78.   /* Make sure there are at least 3 arguments */
  79.   if (argc < 4)
  80.     {
  81.       (VOID) fprintf (stderr, ErrMsg);
  82.       (VOID) fprintf (stderr, Usage, argv[0]);
  83.       exit (EXIT_ERR);
  84.     }
  85.  
  86.   /* Initialize program */
  87.   (VOID) TInit (DVpath, (CHAR *) NULL);
  88.   screen = TscOpen (argv[1], (CHAR *) NULL);
  89.   view = TviLoad (argv[2]);
  90.   drawport = TdpCreate (screen, view, (RECTANGLE *) NULL,
  91.                         (RECTANGLE *) NULL);
  92.  
  93.   /* Setup argument block to pass to TobForEachSubobject */
  94.   arg.d = TviGetDrawing (view); /* arg.d is the drawing */
  95.   if (argc >= 5)                /* arg.f is the font name */
  96.     arg.f = (char *) VIstrclone (argv[4]);
  97.   else
  98.     arg.f = (char *) VIstrclone ("roman.vf");
  99.   if (argc == 6)                /* font scale (uniform) */
  100.     (VOID) sscanf (argv[5], "%f", &scale);
  101.   if (argc == 7)
  102.     {                           /* font height and width */
  103.       userset = 1;
  104.       (VOID) sscanf (argv[5], "%f", &fh);
  105.       (VOID) sscanf (argv[6], "%f", &fw);
  106.     }
  107.  
  108.   /* Recursively replace all regular text object */
  109.   (VOID) TobForEachSubobject (arg.d,
  110.                   (TOBFOREACHSUBOBJFUNPTR)ReplaceTextWithVtext,
  111.                               (ADDRESS) & arg);
  112.  
  113.   /* Save new view file and clean-up */
  114.   if (!TviSave (view, argv[3]))
  115.     (VOID) fprintf (stderr, "%s: Could not save view\n", argv[3]);
  116.   TdpFree (drawport);
  117.   (VOID) TscClose (screen);
  118.   (VOID) TTerminate ();
  119.   return EXIT_OK;
  120. }
  121.  
  122. ADDRESS 
  123. ReplaceTextWithVtext (object, arg)
  124.      OBJECT object;
  125.      argblock *arg;
  126. {
  127.   INT objtype;
  128.   CHAR *string;
  129.   OBJECT ptobj, vtobj;
  130.   OBJECT drawing;
  131.   DV_POINT scp, wcp, woff;
  132.   ARGBLOCK subarg;
  133.   ATTRIBUTES attr;
  134.   RECTANGLE wvp, svp;
  135.   OBJECT dyn_obj;
  136.  
  137.   /* The drawing object containing the current object is arg->d */
  138.   drawing = arg->d;
  139.  
  140.   /* If it is of text type replace it with vector text,
  141.      else if it is a subdrawing, descend recursively and repeat,
  142.      else just ignore.  */
  143.   if ((objtype = VOobType (object)) == OT_TEXT)
  144.     {
  145.       /* construct a close match of regular text with vector text */
  146.       ptobj = VOobPtGet (object, 1);
  147.       VOobAtGet (object, &attr);
  148.       attr.text_fontname = (char *) VIstrclone (arg->f);
  149.       attr.text_width = fw;
  150.       attr.text_height = fh;
  151.       attr.text_angle = attr.text_slant = 0;
  152.       attr.text_charspace = attr.text_linespace = 0;
  153.       string = (char *) VIstrclone (VOtxGetString (object));
  154.       vtobj = VOvtCreate (string, VOobClone (ptobj), &attr);
  155.       if (!userset)
  156.         {
  157.           VOobBox (object, &wvp, &svp);
  158.           scp.x = DV_VIABS (svp.ur.x - svp.ll.x);
  159.           scp.y = DV_VIABS (svp.ur.y - svp.ll.y);
  160.           (VOID) TdpScreenToWorld (drawport, &scp, &wcp);
  161.           scp.x = 0;
  162.           scp.y = 0;
  163.           (VOID) TdpScreenToWorld (drawport, &scp, &woff);
  164.           attr.text_width = wcp.x - woff.x;
  165.           attr.text_height = wcp.y - woff.y;
  166.           VOobBox (vtobj, &wvp, &svp);
  167.           attr.text_width /= DV_VIABS (wvp.ur.x - wvp.ll.x);
  168.           attr.text_height /= DV_VIABS (wvp.ur.y - wvp.ll.y);
  169.           if (scale)
  170.             {
  171.               attr.text_width *= scale;
  172.               attr.text_height *= scale;
  173.             }
  174.           VOobAtSet (vtobj, &attr);
  175.         }
  176.       dyn_obj = VOobDyGet (object);
  177.       if (dyn_obj)
  178.         VOobDySet (vtobj, dyn_obj);
  179.  
  180.       (VOID) VOdrObReplace (drawing, object, vtobj);    /* replace! */
  181.  
  182.  
  183.     }
  184.   else if (objtype == OT_SUBDRAWING)
  185.     {
  186.       /* descend recursively if the object happens to be a subdrawing
  187.          and search again for regular text to replace */
  188.       subarg.d = VOsdDrGet (object);
  189.       subarg.f = (char *) VIstrclone (arg->f);
  190.       (VOID) TobForEachSubobject (subarg.d,
  191.                   (TOBFOREACHSUBOBJFUNPTR)ReplaceTextWithVtext,
  192.                                   (ADDRESS) & subarg);
  193.     }
  194.   return NULL;
  195. }
  196.  
  197. LOCAL char *
  198. VIstrclone (str)
  199.      char *str;
  200. {
  201.   INT len;
  202.   CHAR *newstr;
  203.  
  204.   if (str == NULL)
  205.     return (NULL);
  206.   len = S_STRLEN (str) + 1;
  207.   newstr = (CHAR *) S_ALLOC (len);
  208.   (VOID) strcpy (newstr, str);
  209.   return (newstr);
  210. }
  211.  
  212. /* DD -----------------------------> end of tx2vt.c ---------------- */
  213.